/***************************************************************************
 *   Copyright (C) 2008 by Rysiek KrÃ³l,,,   *
 *   rysiek@Babylon2   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#ifndef IMAGELOADER_H
#define IMAGELOADER_H

#include <QThread>
#include <QWaitCondition>
#include <QMutex>
#include <QImage>
#include <QSize>

#include "property.h"

class PictureListWidgetItem;
class PictureManager;
class QImage;

/**
	@author Rysiek Krol <rysiek.krol@gmail.com>
*/
class ImageLoader : public QThread
{
        Q_OBJECT
public:
        enum Action {GetNext=1, GetPrevious=2, GetIndex=3, GetCurrent=4, GetNextAndReload=5};
        ImageLoader( PictureManager *manager);
        ~ImageLoader();
        void setCurrentIndex(int theValue);
        int getCurrentIndex() const;
        void setCurrentAction(const Action& theValue);
        Action getCurrentAction() const;
        void setGoToSleepFalse();


        QWaitCondition newActionCondition;
        QMutex waitMutex;


protected:
        void run();

private:
        Action currentAction;
        PictureManager *manager;
        QImage nextImage;
        QImage currentImage;
        QImage previousImage;
        QSize size;
        int currentIndex;
        bool goToSleep;
        void sendIndexedImage();
        void sendNextImage();
        void sendNextAndReload();
        void sendPreviousImage();
        void sendCurrentImage();
        void reloadImages();
        QImage getScaledImage(QImage image);

private slots:
        void propertyChangedSlot(Property::PropertyType typ);
};

#endif
